package abinly.harmony.permission.compiler;

import abinly.harmony.permission.NeedsCallingOrSelfPermission;
import abinly.harmony.permission.NeedsCallingPermission;
import abinly.harmony.permission.NeedsSelfPermission;
import abinly.harmony.permission.OnPermissionBlocked;

import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.Name;
import javax.lang.model.type.DeclaredType;

public final class AnnotationChecker {

    private AnnotationChecker(){}

    public static boolean isNeedsSelfPermissionAnnotation(AnnotationMirror annotationMirror) {
        return isSpecifyAnnotation(annotationMirror, NeedsSelfPermission.class);
    }

    public static boolean isNeedsCallingOrSelfPermissionAnnotation(AnnotationMirror annotationMirror) {
        return isSpecifyAnnotation(annotationMirror, NeedsCallingOrSelfPermission.class);
    }

    public static boolean isNeedsCallingPermissionAnnotation(AnnotationMirror annotationMirror) {
        return isSpecifyAnnotation(annotationMirror, NeedsCallingPermission.class);
    }

    public static boolean isOnPermissionBlockedAnnotation(AnnotationMirror annotationMirror) {
        return isSpecifyAnnotation(annotationMirror, OnPermissionBlocked.class);
    }

    private static boolean isSpecifyAnnotation(AnnotationMirror annotationMirror, Class annotationClass) {
        DeclaredType declaredType = annotationMirror.getAnnotationType();
        Name annotationName = declaredType.asElement().getSimpleName();
        return annotationClass.getSimpleName().contentEquals(annotationName);
    }

}
